package com.studypartner;

import java.util.ArrayList;

import com.studypartner.tasks.DailyTask;
import com.studypartner.tasks.TaskService;
import com.studypartner.util.MyMenu;
import com.studypartner.util.TimeUtils;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TableLayout;

public class Activity_Tasks extends Activity {

	private TableLayout tableLayout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_activity__tasks);
		tableLayout = (TableLayout) this.findViewById(R.id.TableLayout1);
		TaskService.loadTasks(this);
		showTasks();

	}

	private void showTasks() {
		ArrayList<DailyTask> dailyTasks = TaskService.getDailyTasks(
				TimeUtils.getCurrentDayOfWeek(), this);
		tableLayout.removeAllViews();
		for (DailyTask dt : dailyTasks) {
			tableLayout.addView(new TaskControl(this, dt));
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		// getMenuInflater().inflate(R.menu.activity__tasks, menu);
		MyMenu.setMyMenu(menu);
		return true;
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		// TODO Auto-generated method stub
		MyMenu.MenuClick(item, this);
		if (item.getItemId() == MyMenu.item_ClearCurrentNum) {
			showTasks();
		}
		return super.onMenuItemSelected(featureId, item);
	}

}
